
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Mydata extends HttpServlet {
  private static final long serialVersionUID = 1L;

  protected void doGet(HttpServletRequest request,
      HttpServletResponse response) throws ServletException, IOException {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();

    Statement st;
    Connection con;
    ResultSet rs;

    ServletContext sc = getServletContext();

    String driver = sc.getInitParameter("driver");
    String url = sc.getInitParameter("url");
    String user = sc.getInitParameter("user");
    String password = sc.getInitParameter("password");

    try {

      Class.forName(driver);
      con = DriverManager.getConnection(url, user, password);
      st = con.createStatement();
      rs = st.executeQuery("select * from stud");

      while (rs.next()) {
        out
            .println("<br>" + rs.getInt(1) + "  "
                + rs.getString("name"));
      }

    } catch (SQLException e) {
      System.err.println(e.getMessage());
      e.printStackTrace();
    } catch (ClassNotFoundException e) {
      // 
    }

  }

}